package com.soul.doc.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.soul.common.msg.ApiResult;
import com.soul.doc.bean.dto.CommentDto;
import com.soul.doc.bean.dto.LikeCommentDto;
import com.soul.doc.bean.vo.CommentVo;
import com.soul.doc.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.soul.common.controller.BaseController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sws
 * @since 2023-12-16 19:27:59
 */
@RestController
@RequestMapping("/comment")
public class CommentController extends BaseController {

    @Autowired
    private CommentService commentService;

    @GetMapping("{page}/{size}/list")
    public ApiResult<IPage<CommentVo>> queryComment(@PathVariable("page") Integer page,
                                                    @PathVariable("size") Integer size,
                                                    CommentDto commentDto){
        IPage<CommentVo> voIPage = commentService.queryComment(page, size, commentDto);
        return ApiResult.success(voIPage);
    }

    @PostMapping("/add")
    public ApiResult<CommentVo> addComment(@RequestBody CommentDto commentDto){
        CommentVo commentVo = commentService.addComment(commentDto);
        return ApiResult.success(commentVo);
    }

    @PostMapping("{id}/delete")
    public ApiResult<?> deleteComment(@PathVariable("id") Long id){
        commentService.deleteComment(id);
        return ApiResult.success();
    }

    @PostMapping("like")
    public ApiResult<CommentVo> likeComment(@RequestBody LikeCommentDto likeCommentDto){
        CommentVo commentVo = commentService.addLike(likeCommentDto);
        return ApiResult.success(commentVo);
    }
}
